﻿@inherits TasksBase

<div class="card">
    <div class="card-header">任务介绍</div>
    <div class="card-body">
        <div class="alert alert-info">
            <p class="font-weight-bold">后台任务说明：</p>
            <p>1. 默认任务 (立即执行，仅执行一次)</p>
            <p>
                <code>
                    TaskServicesManager.GetOrAdd("简单任务", token => Task.Delay(1000));
                </code>
            </p>
            <p>2. 周期性任务 (1 分钟后间隔 5 秒执行 2 次任务)</p>
            <p>
                <code>
                    var trigger = TriggerBuilder.Default.WithInterval(TimeSpan.FromSeconds(5)).WithRepeatCount(2).WithStartTime(DateTimeOffset.Now.AddMinutes(1)).Build();
                    <br />
                    TaskServicesManager.GetOrAdd("测试任务", token => Task.Delay(1000), trigger);
                </code>
            </p>
            <p>3. Cron 表达式任务 (间隔 5 秒循环执行任务)</p>
            <div>
                <code>
                    TaskServicesManager.GetOrAdd("Cron 表达式任务", token => Task.Delay(1000), TriggerBuilder.Build("*/5 * * * * *"));
                </code>
            </div>
        </div>
    </div>
</div>

<div class="card">
    <div class="card-header">
        <span>查询结果</span>
    </div>
    <div class="card-body">
        <ConditionComponent>
            <div class="alert alert-danger" role="alert">
                <span>演示系统禁止修改定时后台任务</span>
            </div>
        </ConditionComponent>
        <Table Id="task" TItem="DefaultScheduler" ShowToolBar="true" ShowRefresh="true" ShowExtendButtons="true" EditModel="DataContext" OnQuery="Query">
            <TableHeader>
                <LgbTableHeader TItem="string" @bind-Value="@context.Name"></LgbTableHeader>
                <LgbTableHeader TItem="DateTimeOffset" @bind-Value="@context.CreatedTime" class="text-nowrap datetime"></LgbTableHeader>
                <LgbTableHeader TItem="DateTimeOffset?" @bind-Value="@context.LastRuntime" class="text-nowrap datetime"></LgbTableHeader>
                <LgbTableHeader TItem="DateTimeOffset?" @bind-Value="@context.NextRuntime" class="text-nowrap datetime"></LgbTableHeader>
                <LgbTableHeader TItem="string" @bind-Value="@context.TriggerExpression"></LgbTableHeader>
                <LgbTableHeader TItem="Longbow.Tasks.TriggerResult" @bind-Value="@context.LastRunResult" class="text-nowrap"></LgbTableHeader>
                <LgbTableHeader TItem="Longbow.Tasks.SchedulerStatus" @bind-Value="@context.Status"></LgbTableHeader>
            </TableHeader>
            <RowTemplate>
                <td class="text-nowrap">@context.Name</td>
                <td>@context.CreatedTime.DateTime</td>
                <td>@context.LastRuntime?.DateTime</td>
                <td>@context.NextRuntime?.DateTime</td>
                <td>@context.TriggerExpression</td>
                <td>@FormatterResult(context.LastRunResult)</td>
                <td>@FormatterStatus(context.Status)</td>
            </RowTemplate>
            <ButtonTemplate>
                <div class='btn-group'>
                    <button class='pause btn btn-sm btn-danger' asp-auth="pause"><i class='fa fa-pause-circle'></i><span>暂停</span></button>
                    <button class='run btn btn-sm btn-success' asp-auth="pause"><i class='fa fa-play-circle'></i><span>运行</span></button>
                    <button class='info btn btn-sm btn-info' asp-auth="info"><i class='fa fa-info-circle'></i><span>日志</span></button>
                </div>
            </ButtonTemplate>
        </Table>
    </div>
</div>
